<template>
    <el-table :data="tableData" border stripe :header-cell-class-name="headerBg"
              @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="id" ></el-table-column>
        <el-table-column prop="name" label="用户" ></el-table-column>
        <el-table-column prop="uploadTime" label="创建时间" ></el-table-column>
        <el-table-column prop="state" label="进度"></el-table-column>
        <el-table-column label="审核" width="350">
            <template v-slot="scope">
                <el-button type="success" @click="terntodetail(scope.row)" :disabled="scope.row.state !== '待审核'">数据详情</el-button>
                <el-button type="success" @click="changeState(scope.row, '审核通过...师傅正在赶来的路上')" :disabled="scope.row.state !== '待审核'">审核通过</el-button>
                <el-button type="danger" @click="changeState(scope.row, '审核不通过')" :disabled="scope.row.state !== '待审核'">审核不通过</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-table :data="datas" style="width: 100%" max-height="500" border>
        <el-table-column fixed label="序号" width="100">
            <template #default="scopes">
                {{ scopes.$index+1 }}
            </template>
        </el-table-column>
        <el-table-column fixed prop="id" label="学号" width="100" />
        <el-table-column fixed prop="name" label="姓名" width="100" />
        <el-table-column prop="major" label="专业" width="100" />
        <el-table-column prop="classi" label="班级" width="100" />
        <el-table-column prop="course" label="科目" width="100" />
        <el-table-column prop="teachername" label="任课教师" width="100" />
        <el-table-column prop="gredit" label="学分" width="100" />
        <el-table-column prop="escore" label="考试成绩" width="100" />
        <el-table-column prop="ascore" label="平时成绩" width="100" />
        <el-table-column prop="fscore" label="总成绩" width="100"  />
    </el-table>
    <div class="pagination">
        <el-pagination
                background
                layout="sizes,prev,pager,next,jumper,->,total"
                :page-size.sync="pageSize"
                :current-page.sync="pageNum"
                :page-sizes="[5,8,10,15]"
                :total="totals"
                :hide-on-single-page="true"
                @current-change="getList"
                @size-change="getList1"
        />
    </div>
</template>
<script setup>
import { get,post } from '@/utils/request.js'
import {ElMessage} from 'element-plus'
import { ref,onMounted } from 'vue'
import moment from 'moment';

const tableData=ref([])
const datas=ref([])
const pageNum=ref(1)
const pageSize=ref(5)
const index=ref(0)
const totals=ref('')
const types=ref('')

onMounted(async () => {
   init();
})

const init=()=>{
 get('/data/all',(message)=>{
     tableData.value = message.map(item=>({
    ...item,
     uploadTime: moment(item.uploadTime).format('YYYY-MM-DD'),
    }))
})
}

const getList=(pageNums)=>{
post('/showpage',{
types:'score_copy',
pageSize:pageSize.value,
pageNum:pageNum.value,
uploadid:index.value
},(message)=>{
datas.value = message.newlist
totals.value=parseInt(message.total)
pageNum.value=pageNums
},(message)=>{
ElMessage.warning(message)
})
}

const getList1=(pageSizes)=>{
post('/showpage',{

},(message)=>{
datas.value = message.newlist
totals.value=parseInt(message.total)
pageSize.value=pageSizes
},(message)=>{
ElMessage.warning(message)
})
}



const terntodetail=(row)=>{
post('/data/terntodetail',{id:row.id},(message)=>{
index.value=row.id
datas.value=message
totals.value=datas.value.length
},(message)=>{
ElMessage.warning(message)
})
}

 const changeState=(row, state)=> {

if(state=='审核通过...师傅正在赶来的路上'){
post('/data/checksuccess',{id:row.id},(message)=>{
init()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}else{
post('/data/checkfailure',{id:row.id},(message)=>{
init()
datas.value=[]
ElMessage.success(message)
},(message)=>{
ElMessage.warning(message)
})
}
      this.form = JSON.parse(JSON.stringify(row))
      this.form.state = state;
      this.save();
    }
</script>
<style scoped>
</style>